/*
 * @Author: yushuang
 * @Date: 2024-12-16 10:30:30
 * @LastEditors: yushuang
 * @LastEditTime: 2024-12-16 10:32:41
 * @Description:
 */
import { useLoading } from '@/composables/base-loading';
import { LoadingEnum } from '@/enums/loading-enum';

const loading = useLoading({
  spin: LoadingEnum.CHASE,
  minTime: 500
});

export class AxiosLoading {
  loadingCount: number;
  constructor() {
    this.loadingCount = 0;
  }

  addLoading() {
    if (this.loadingCount === 0) loading.open();

    this.loadingCount++;
  }

  closeLoading() {
    if (this.loadingCount > 0) {
      if (this.loadingCount === 1) loading.close();
      this.loadingCount--;
    }
  }
}
